IF EXISTS (SELECT 1
          FROM SYSOBJECTS
          WHERE  id = OBJECT_ID('USP_UpdateOnlineStaff')
          AND TYPE IN ('P','PC'))
   DROP PROCEDURE USP_UpdateOnlineStaff
GO

/****** Object:  StoredProcedure [dbo].[USP_UpdateOnlineStaff]    Script Date: 10/20/2010 15:51:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Boonyarit
-- Create date: 26/11/2010
-- exec[USP_UpdateOnlineStaff]
-- =============================================
CREATE PROCEDURE [dbo].[USP_UpdateOnlineStaff]
	-- Add the parameters for the stored procedure here
	@staff_online_id int,
	@staff_code int,
	@session_id varchar(50),
	@ip_address varchar(50),
	@active bit
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	if @staff_online_id > 0 
		update staff_online
			set session_id = @session_id,
				last_update_datetime = GETDATE(),
				active = @active
		where staff_online_id = @staff_online_id
	else
		update staff_online
			set last_update_datetime = GETDATE(),
				active = @active
		where staff_code = @staff_code
				and session_id = @session_id
				and ip_address = @ip_address

END

GO
